<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="submitSave">提交</button>
    <button form-type="reset">重置</button>
    <button>保存</button>
    <button>选中</button>
    <script>
        var submitSave = document.getElementById('submitSave');
        submitSave.onclick = async function saveFile() {
            try {
                const opts = {
                    types: [
                        {
                            description: 'WebsiteTemplate文件',
                            accept: {
                                'text/plain': ['.wTmpl'],
                            }
                        }
                    ],
                    excludeAcceptAllOption: true
                };

                const handle = await window.showSaveFilePicker(opts); // 打开保存文件对话框
                const writable = await handle.createWritable(); // 创建可写入的文件对象

                var name = handle.name;
                //名称 加密
                var fileContent = `<!WebsiteTemplate{Password:${name}}>` + document.getElementById('writeBoard').innerHTML;
                var result = btoa(fileContent)
                // 在这里写入文件内容
                await writable.write(result);
                await writable.close();

                console.log('文件保存成功');
                window.alert('success');
            } catch (error) {
                console.error('文件保存失败:', error);
            }
        }
    </script>
</body>

</html>